<?php

namespace App\Http\Service;

use App\Models\Viewcountmore;
use App\Models\Doubanpost;
use App\Models\Baoliaopost;
use App\Http\Service\BaseService;
use App\Http\Service\ChatgptService;
use App\Http\Service\UserService;
use App\Http\Service\SiteConfigService;
use App\Models\Weibopost;

class WeiboService  extends BaseService
{
    private $model;
    public  $userService;
    public function __construct(Weibopost $model,ChatgptService $chatgptService,UserService  $userService,SiteConfigService $siteConfigService,Doubanpost $doubanpost,Baoliaopost $baoliaopost)
    {
        parent::__construct();
        $this->model = $model;
        $this->chatgptService=$chatgptService;
        $this->userService=$userService;
        $this->siteConfigService=$siteConfigService;
        $this->doubanpost=$doubanpost;
        $this->baoliaopost=$baoliaopost;

       
    }

    
    #微博
    public function addData($request,$data=[])
    {

        $unique_id=$data['unique_id'];
        //获取所有json数据
        $jsonData = $request->all();
        $data['json_data']=json_encode($jsonData, JSON_UNESCAPED_UNICODE);

        //dd($res);
        $post_data=[
            'json_data'=>$data['json_data'],
            'unique_id'=>$data['unique_id'],
            'article_id'=>$data['article_id'],
            'avatar'=>$data['avatar'],
            'user_id'=>$data['user_id'],
            'nickname'=>$data['nickname'],
            'content_books'=>$data['content'],
            'images'=>$data['images'],
            'has_retweet'=>$data['has_retweet'],
            'product_num'=>$data['product_num'],
            'retweeted_content'=>$data['retweeted_content'],
            'publish_time'=>$data['publish_time'],
            'is_weibo_chaohua'=>$data['is_weibo_chaohua'],
            'article_detail_url'=>$data['article_detail_url'],
            'like_count'=>'0',
            'collect_count'=>'0',
            'comment_count'=>'0',
            'view_count'=>'0',

            'status'=>'1',

        ];
        //dd($post_data);
        $post_info=$this->model->where(['unique_id'=>$data['unique_id']])->first();
        
        if($post_info){
            
            $post_data['create_time'] =date("Y-m-d H:i:s");
            //dd($post_data);
            $this->model->where(['unique_id'=>$data['unique_id']])->update($post_data);
            $post_id=$post_info['id'];

        }else{
            $post_data['create_time'] =date("Y-m-d H:i:s");
            $post_data['update_time'] =date("Y-m-d H:i:s");
            $post_id=$this->model->insertGetId($post_data);

        }
        //dd($post_id);
        return($post_data);
        
    }
  
}
